using System;
using Microsoft.Practices.Unity;
using Sogeti.Guidelines.WCF.Extensions;

namespace Sogeti.Guidelines.Unity.WCF
{
    public class WcfServiceInstanceLifeTimeManager : LifetimeManager
    {
        private readonly Guid _key;

        public WcfServiceInstanceLifeTimeManager()
        {
            _key = Guid.NewGuid();
        }

        public override object GetValue()
        {
            return InstanceItemsExtension.Current.Items.Find(_key);
        }

        public override void SetValue(object newValue)
        {
            InstanceItemsExtension.Current.Items.Set(_key, newValue);
        }

        public override void RemoveValue()
        {
            InstanceItemsExtension.Current.Items.Remove(_key);
        }
    }
}